﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace PcArduinoControl
{
	class Message :
		Packet
	{
		private static byte[] CombineTypeAndArgs(MessageType type, byte[] args)
		{
			byte[] data = new byte[1];

			data[0] = (byte)type;
			data = data.Concat(args).ToArray();
			return data;
		}

		byte mStatedChecksum;

		public override byte StatedChecksum
		{
			get
			{
				return mStatedChecksum;
			}
		}

		public MessageType Type
		{
			get
			{
				return (MessageType)Data[0];
			}
		}

		public byte[] Arguments
		{
			get
			{
				return Data.Skip(1).ToArray();
			}
		}

		internal Message(byte id, byte statedChecksum, MessageType type) :
			this(id, statedChecksum, type, new byte[0])
		{
		}

		internal Message(byte id, byte statedChecksum, MessageType type, IEnumerable<byte> args) :
			this(id, statedChecksum, type, args.ToArray())
		{
		}

		internal Message(byte id, byte statedChecksum, MessageType type, byte[] args) :
			base(id, Direction.ArduinoToPc, CombineTypeAndArgs(type, args))
		{
			mStatedChecksum = statedChecksum;
		}
	}
}
